import threading
import time

"""
1.多线程程序的执行顺序是不确定的
2.主线程会等待所有的子线程执行结束再结束
class MyThread(threading.Thread):
    def run(self):
        for i in range(3):
            time.sleep(1)
            msg = "I'm "+self.name+' @ '+str(i)
            print(msg)


def test():
    for i in range(5):
        t = MyThread()
        t.start()
if __name__ == '__main__':
    test()
"""

"""守护主线程
守护主线程就是主线程退出子线程销毁不再执行

设置守护主线程有两种方式：
    1.threading.Thread(target=show_info, daemon=True)
    2.线程对象.setDaemon(True)
"""
def show_info():
    for i in range(5):
        print("子线程....{}.....".format(i))
        time.sleep(1)

if __name__ == '__main__':
    # 方式1
    #t = threading.Thread(target=show_info, daemon=True)
    t = threading.Thread(target=show_info)
    # 方式2
    t.setDaemon(True)
    t.start()

    time.sleep(1)
    print('main over')

















